<template>
  <view style="height: 100vh; width: 200rpx; display: flex; align-items: center; margin: 0 auto">
    <u-button type="primary" @click="goHome">返回</u-button>
  </view>
</template>
<script setup lang="ts">
import { createOrder } from "@/api/my";
import { loginFn } from "@/utils/commonFn";
import { onMounted } from "vue";
const { id } = defineProps<{
  id: string;
}>();
onMounted(async () => {
  await loginFn();
  const res = await createOrder({ id });
  let orderInfo: any = res.data;
  uni.requestPayment({
    provider: "wxpay",
    orderInfo,
    ...orderInfo,
    success(res: any) {
      if (res.errMsg == "requestPayment:ok") {
        uni.showToast({
          title: "购买成功",
          icon: "success",
        });
      }
    },
    fail() {
      uni.showToast({
        title: "购买失败",
        icon: "error",
      });
    },
  });
});
const goHome = () => {
  uni.switchTab({
    url: "/pages/home/home",
  });
};
</script>
<style lang="less" scoped></style>
